package com.ygq.Impl;

import DO.TeacherDO;
import DTO.AddTeacherDTO;
import DTO.EditStudentPasswordDTO;
import com.ygq.TeacherService;
import mapper.TeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import result.Result;

import java.util.List;
import java.util.Objects;


@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    // 获取教师信息
    public List<TeacherDO> getTeachers() {
        return teacherMapper.getTeachers();
    }


    // 查询出教师袁勋的教师id
    public Integer getTeacherByEleve() {
        return teacherMapper.getTeacherByeleve(1);
    }


    // 重置密码
    public void resetTeacherPassword(Integer id,String password) {
        teacherMapper.resetTeacherPassword(id, password);
    }

    // 删除教师
    public void deleteTeacher(Integer id) {
        teacherMapper.deleteTeacher(id);
    }

    // 添加教师助手
    public void save(AddTeacherDTO addTeacherDTO, String password) {
        teacherMapper.save(addTeacherDTO.getUsername(),addTeacherDTO.getUserNumber(),password);
    }

    // 修改密码
    public Result<String> updatePassword(EditStudentPasswordDTO editStudentPasswordDTO) {
        String password = teacherMapper.getPasswordById(editStudentPasswordDTO.getId());
        if (!Objects.equals(password, editStudentPasswordDTO.getOldPassword())){
            return Result.error("密码错误",401);
        }
        teacherMapper.updatePassword(editStudentPasswordDTO.getNewPassword(), editStudentPasswordDTO.getId());
        return Result.success("ok");
    }
}
